package cn.cdeden.knowledge.controller.message;

import cn.cdeden.common.core.domain.R;
import cn.cdeden.common.core.utils.page.TableDataInfo;
import cn.cdeden.common.satoken.utils.LoginHelper;
import cn.cdeden.knowledge.domain.dto.*;
import cn.cdeden.knowledge.domain.vo.SysMessageVo;
import cn.cdeden.knowledge.service.SysMessageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;


@Controller
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/message")
public class MessageController {

    private final SysMessageService sysMessageService;


    /**
     * 查询消息
     * @return
     */
//    @Log("查询消息")
//    @ApiOperation("查询消息" )
    @GetMapping(value = "/getMessageByUser")
    @ResponseBody
    public R<TableDataInfo<SysMessageVo>> getMessageByUser(SysMessageQueryParam query, Pageable pageable){
        return R.ok(sysMessageService.getMessageByUser(query,pageable));
    }

    /**
     * 设置已读
     * @return
     */
    @PostMapping(value = "/readMessage")
    @ResponseBody
    public R<Boolean> readMessage(@RequestBody Long messageId){
        return R.ok(sysMessageService.readMessage(messageId));
    }

    /**
     * 全部消息设置已读
     * @return
     */
    @PostMapping(value = "/readMessageAll")
    @ResponseBody
    public R<Boolean> readMessageAll(){
        return R.ok(sysMessageService.readMessageAll(String.valueOf(LoginHelper.getUserId())));
    }

    /**
     * 消息删除
     * @return
     */
    @DeleteMapping(value = "/{ids}")
    @ResponseBody
    public R<Boolean> removeByIds(@PathVariable Long[] ids){
        return R.ok(sysMessageService.removeByIds(List.of(ids)));
    }
}
